package com.yanqu.road.server.agent.inter;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.enums.eAgentErrorCode;
import com.yanqu.road.server.agent.AgentInterfaceMgr;
import com.yanqu.road.server.manger.robot.RobotMgr;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/5/15 15:30
 */
public class AgentRobot {
    public String oneKeySeniorAccount(JSONObject param) {
        JSONObject ret = AgentInterfaceMgr.getDefaultRet();
        List<Long> errorUserIdList = new ArrayList<>();
        JSONArray jsonArray = param.getJSONArray("param");
        for (Object jsonObject : jsonArray) {
            JSONObject obj = (JSONObject) jsonObject;
            long userId = obj.getLong("userId");
            int level = obj.getIntValue("lv");
            RobotMgr.initPlayerGameData(userId, level, errorUserIdList);
        }
        if (errorUserIdList.size() > 0) {
            String errorMsg = "出错用户id:";
            for (Long errorUserId : errorUserIdList) {
                errorMsg += errorUserId + ";";
            }
            ret.put("msg", errorMsg);
        }
        AgentInterfaceMgr.setCommonRet(ret, eAgentErrorCode.Success.getValue());
        return ret.toString();
    }
}
